import { defineStore } from "pinia"
 
export default defineStore("ToDoList", {
  state: () => {
    return {
      todoListArr: [
        { name: "旅游推荐", flag: false },
        { name: "旅游推荐", flag: false },
        { name: "旅游推荐", flag: false },
      ],
    }
  },
  actions: {
    addToDo(todo) {
      this.todoListArr.push(todo)
    },
    deleteToDo(todo) {
      this.todoListArr.splice(this.todoListArr.indexOf(todo), 1)
    },
    deleteToDoBatch(todos) {
      todos.value.forEach((item) => {
        this.todoListArr.forEach((i) => {
          if (item == i.name)
            this.todoListArr.splice(this.todoListArr.indexOf(i), 1)
        })
      })
    },
  },
  getters: {},
  persist: {
    enabled: true,
    strategies: [
      {
        key: "todolist",
        // storage: sessionStorage,
      },
    ],
  },
  persist: {
    // 调整为兼容多端的API !!!!!!!!
    storage: {
      setItem(key, value) {
        uni.setStorageSync(key, value)
      },
      getItem(key) {
        return uni.getStorageSync(key)
      },
    },
  },

})